//
//  SetMailViewController.m
//  babyMemoryPro
//
//  Created by student on 15-7-1.
//  Copyright (c) 2015年 niit. All rights reserved.
//

#import "SetMailViewController.h"

@interface SetMailViewController ()

@end

@implementation SetMailViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

- (IBAction)btnPressed:(id)sender {
    Class mailClass=(NSClassFromString(@"MFMailComposeViewController"));
    if (!mailClass) {
        NSLog(@"当前设备不支持发送邮件功能");
        return;
    }
    if (![mailClass canSendMail]) {
        NSLog(@"用户没有设置邮件账户");
        return;
    }
    [self setMail];
    
}

-(void)setMail{
    MFMailComposeViewController *mailController=[[MFMailComposeViewController alloc]init];
    mailController.view.bounds=self.view.bounds;
    mailController.mailComposeDelegate=self;
    [mailController setSubject:@"宝宝成长录反馈信息"];
    NSArray *emailAddress;
    emailAddress=@[@"iosCai@163.com"];
    [mailController setToRecipients:emailAddress];
    NSString *emailBody=self.textField.text;
    [mailController setMessageBody:emailBody isHTML:YES];
    [self presentViewController:mailController animated:YES completion:nil];

}
-(void)mailComposeController:(MFMailComposeViewController *)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError *)error{
    //关闭发送邮件窗口
    [self dismissViewControllerAnimated:YES completion:nil];
    NSString *msg;
    /*
     MFMailComposeResultCancelled,
     MFMailComposeResultSaved,
     MFMailComposeResultSent,
     MFMailComposeResultFailed
     */
    switch (result) {
        case MFMailComposeResultCancelled:
            msg=@"用户取消发送邮件";
            break;
        case MFMailComposeResultSaved:
            msg=@"用户成功保存邮件";
            break;
        case MFMailComposeResultSent:
            msg=@"用户成功发送邮件";
            break;
        case MFMailComposeResultFailed:
            msg=@"用户发送邮件失败";
            break;
            
        default:
            break;
    }
    NSLog(@"%@",msg);
}

-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{
    [self.view endEditing:YES];
}


@end
